﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ValidationToolTip.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="textBox"
                     TargetType="TextBox">
        <Grid x:Name="RootElement">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused">
                        <Storyboard>
                            <DoubleAnimation Duration="0"
                                             To="1"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="FocusVisualElement" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Unfocused">
                        <Storyboard>
                            <DoubleAnimation Duration="0"
                                             To="0"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="FocusVisualElement" />
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ValidationStates">
                    <VisualState x:Name="Valid" />
                    <VisualState x:Name="InvalidUnfocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                           Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="InvalidFocused">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                           Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen"
                                                           Storyboard.TargetName="validationTooltip">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <s:Boolean>True</s:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border x:Name="Border"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Background="{TemplateBinding Background}"
                    CornerRadius="3"
                    Opacity="1">
                <Grid>
                    <Border x:Name="ReadOnlyVisualElement"
                            Background="#5EC9C9C9"
                            Opacity="0" />
                    <Border x:Name="MouseOverBorder"
                            BorderBrush="Transparent"
                            BorderThickness="1">
                        <ScrollViewer x:Name="ContentElement"
                                      BorderThickness="0"
                                      IsTabStop="False"
                                      Padding="{TemplateBinding Padding}" />
                    </Border>
                </Grid>
            </Border>
            <Border x:Name="DisabledVisualElement"
                    BorderBrush="#A5F7F7F7"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Background="#A5F7F7F7"
                    IsHitTestVisible="False"
                    Opacity="0" />
            <Border x:Name="FocusVisualElement"
                    BorderBrush="White"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    IsHitTestVisible="False"
                    Margin="1"
                    Opacity="0" />
            <Border x:Name="ValidationErrorElement"
                    BorderBrush="#FFDB000C"
                    BorderThickness="1"
                    CornerRadius="1"
                    Visibility="Collapsed">
                <ToolTipService.ToolTip>
                    <ToolTip x:Name="validationTooltip"
                             DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                             Placement="Right"
                             PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                             Template="{StaticResource ValidationToolTipTemplate}">
                        <ToolTip.Triggers>
                            <EventTrigger RoutedEvent="Canvas.Loaded">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible"
                                                                       Storyboard.TargetName="validationTooltip">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <s:Boolean>true</s:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </ToolTip.Triggers>
                    </ToolTip>
                </ToolTipService.ToolTip>
                <Grid Background="Transparent"
                      HorizontalAlignment="Right"
                      Height="12"
                      Margin="1,-4,-4,0"
                      VerticalAlignment="Top"
                      Width="12">
                    <Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
                          Fill="#FFDC000C"
                          Margin="1,3,0,0" />
                    <Path Data="M 0,0 L2,0 L 8,6 L8,8"
                          Fill="#ffffff"
                          Margin="1,3,0,0" />
                </Grid>
            </Border>
        </Grid>
    </ControlTemplate>

</ResourceDictionary>
